package com.yys.huarongdao.utils;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

import com.yys.huarongdao.BgmIntentService;

public class BgmUtil {

    public final static int STATUS_BGM_OPEN =0;
    public final static int STATUS_BGM_CLOSE =1;
    public final static int STATUS_BGM_PAUSE=2;

    private static int bgmStatus=STATUS_BGM_CLOSE;

//    public final static int STATUS_BGM_OPEN =0;
//    public final static int STATUS_BGM_CLOSE =1;


    public static void openBgm(Context context){
        startBgmService(context, STATUS_BGM_OPEN);
        setBgmStatus(STATUS_BGM_OPEN);
    }
    public static void closeBgm(Context context){
        startBgmService(context, STATUS_BGM_CLOSE);
        setBgmStatus(STATUS_BGM_CLOSE);
    }

    public static void pauseBgm(Context context){
        startBgmService(context,STATUS_BGM_PAUSE);
        setBgmStatus(STATUS_BGM_PAUSE);
    }

    private static void startBgmService(Context context, int switchStatus){
        ComponentName stopComponent =new ComponentName("com.yys.huarongdao","com.yys.huarongdao.BgmIntentService");
        Intent intent=new Intent();
        intent.setComponent(stopComponent);
        intent.setAction(BgmIntentService.ACTION_MUSIC);
        intent.putExtra("switchStatus", switchStatus);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            context.startForegroundService(intent);
        } else {
            context.startService(intent);
        }
    }

    public static int getBgmStatus() {
        return bgmStatus;
    }

    public static void setBgmStatus(int bgmStatus){
        BgmUtil.bgmStatus=bgmStatus;
    }

    public static boolean BgmPlaying(){
        if(bgmStatus==STATUS_BGM_OPEN)
            return true;
        else
            return false;
    }
}
